package com.woniu.intlet.web;

import com.woniu.outlet.dao.ProProgressPoMapper;
import com.woniu.outlet.po.ProPlanPo;
import com.woniu.outlet.po.ProProgressPo;
import com.woniu.service.ProPlanPoService;
import com.woniu.uitl.ResponseResult;
import com.woniu.uitl.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "提供外部公共接口")
@Slf4j
public class OutCommand {

    @Autowired
    private ProProgressPoMapper proProgressPoMapper;
    @Autowired
    private ProPlanPoService proPlanPoService;

    @PostMapping("addProProgress")
    @ApiOperation("添加生产进度信息")
    public ResponseResult<String> addProProgress(@RequestBody ProProgressPo po){
        try {
            proProgressPoMapper.insertSelective(po);
            return new ResponseResult<String>("添加成功","添加成功",ResultCode.SUCCESS.getCode());
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<String>("添加失败"+e.getMessage(),"添加失败"+e.getMessage(),ResultCode.SUCCESS.getCode());
        }
    }

    @GetMapping("getPlanByOrderId")
    @ApiOperation("根据订单id查询生产计划信息")
    public ResponseResult<ProPlanPo> findAllProPlan(Long orderId){
        log.info(orderId.toString());
        List<ProPlanPo> poList = proPlanPoService.findAllProPlan(orderId,null);
        log.info("111");
        return new ResponseResult<ProPlanPo>(poList.get(0),"OK",ResultCode.SUCCESS.getCode());
    }

}
